package main

import (
	"fmt"
	_ "sync"
	"threadpoolpro/threadpool"
	"time"
)

type MyTask struct {
	name int
}

func (mytask MyTask) Task() {

	fmt.Println(mytask.name)
	time.Sleep(time.Duration(5-mytask.name+1) * time.Second)
	fmt.Println(mytask.name, "任务结束")
}

func (mytask MyTask) GetName() int {
	return mytask.name
}

func NewTask(n int) MyTask {
	return MyTask{
		name: n,
	}
}

func main() {
	// rand.Seed(time.Now().UnixNano())
	// time.Sleep(time.Duration(rand.Intn(10)) * time.Second)
	p := threadpool.GetPool(3, 10, 6)
	p.Run()
	// rand.Seed(time.Now().UnixNano())
	for i := 0; i < 5; i++ {
		// fmt.Println("等我", 5-i, "秒，我生成一个任务！！")
		// time.Sleep(time.Duration(5-i) * time.Second)
		p.AddTask(NewTask(i + 1))
	}
	p.WaitFinish()
	// rand.Seed(time.Now().UnixNano())
	// for i := 0; i < 5; i++ {
	// 	fmt.Println(rand.Intn(10))
	// }

}
